load("//bazel:ray.bzl", "ray_cc_library")

ray_cc_library(
    name = "core_worker_lib",
    srcs = [
        "core_worker.cc",
        "core_worker_process.cc",
    ],
    hdrs = [
        "core_worker.h",
        "core_worker_process.h",
    ],
    deps = [
        ":actor_handle",
        ":actor_manager",
        ":core_worker_common",
        ":core_worker_context",
        ":core_worker_options",
        ":experimental_mutable_object_manager",
        ":experimental_mutable_object_provider",
        ":future_resolver",
        ":generator_waiter",
        ":memory_store",
        ":normal_task_submitter",
        ":object_recovery_manager",
        ":plasma_store_provider",
        ":profile_event",
        ":reference_count",
        ":task_event_buffer",
        ":task_receiver",
        "//src/ray/raylet_client:raylet_client_lib",
        "//src/ray/gcs/gcs_client:gcs_client_lib",
        "//src/ray/gcs:gcs_pb_util",
        "//src/ray/pubsub:pubsub_lib",
        "//:worker_rpc",
        "//src/ray/common/cgroup:cgroup_context",
        "//src/ray/common/cgroup:cgroup_manager",
        "//src/ray/common/cgroup:constants",
        "//src/ray/protobuf:pubsub_cc_proto",
        "//src/ray/stats:stats_lib",
        "//src/ray/util",
        "//src/ray/util:container_util",
        "//src/ray/util:env",
        "//src/ray/util:event",
        "//src/ray/util:mutex_protected",
        "//src/ray/util:process",
        "//src/ray/util:shared_lru",
        "//src/ray/util:stream_redirection",
        "//src/ray/util:stream_redirection_options",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_library(
    name = "core_worker_options",
    hdrs = ["core_worker_options.h"],
    deps = [
        ":core_worker_common",
        "//src/ray/gcs/gcs_client:gcs_client_lib",
        "//src/ray/common:id",
        "//src/ray/common:ray_object",
        "//src/ray/common:status",
        "//src/ray/common:task_common",
        "//src/ray/util:process",
    ],
)

ray_cc_library(
    name = "core_worker_fiber",
    hdrs = ["fiber.h"],
    deps = [
        "//src/ray/util:logging",
        "@boost//:fiber",
    ],
)

ray_cc_library(
    name = "actor_submit_queue",
    hdrs = ["transport/actor_submit_queue.h"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "@com_google_absl//absl/types:optional",
    ],
)

ray_cc_library(
    name = "scheduling_queue",
    hdrs = ["transport/scheduling_queue.h"],
    deps = [
        "//:rpc_server_call",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:worker_cc_proto",
    ],
)

ray_cc_library(
    name = "core_worker_common",
    srcs = ["common.cc"],
    hdrs = ["common.h"],
    deps = [
        "//src/ray/raylet_client:raylet_client_lib",
        "//src/ray/common:id",
        "//src/ray/common:ray_object",
        "//src/ray/common:task_common",
    ],
)

ray_cc_library(
    name = "core_worker_context",
    srcs = ["context.cc"],
    hdrs = ["context.h"],
    deps = [
        ":core_worker_common",
        "//src/ray/common:runtime_env",
        "//src/ray/common:task_common",
        "@boost//:thread",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/synchronization",
        "@nlohmann_json",
    ],
)

ray_cc_library(
    name = "actor_handle",
    srcs = ["actor_handle.cc"],
    hdrs = ["actor_handle.h"],
    deps = [
        ":core_worker_context",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:gcs_cc_proto",
        "//src/ray/protobuf:worker_cc_proto",
        "@com_google_absl//absl/types:optional",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_library(
    name = "actor_creator",
    hdrs = ["actor_creator.h"],
    deps = [
        "//src/ray/gcs/gcs_client:gcs_client_lib",
        "//src/ray/common:ray_config",
    ],
)

ray_cc_library(
    name = "actor_manager",
    srcs = ["actor_manager.cc"],
    hdrs = ["actor_manager.h"],
    deps = [
        ":actor_creator",
        ":actor_handle",
        ":actor_task_submitter",
        ":core_worker_common",
        ":core_worker_context",
        ":reference_count",
        ":task_receiver",
        "//src/ray/gcs/gcs_client:gcs_client_lib",
        "//src/ray/gcs:gcs_pb_util",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:worker_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_library(
    name = "reference_count",
    srcs = ["reference_count.cc"],
    hdrs = ["reference_count.h"],
    deps = [
        ":lease_policy",
        "//:grpc_server",
        "//src/ray/pubsub:pubsub_lib",
        "//:worker_rpc",
        "//src/ray/common:id",
        "//src/ray/protobuf:common_cc_proto",
        "//src/ray/util:logging",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "lease_policy",
    srcs = ["lease_policy.cc"],
    hdrs = ["lease_policy.h"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
    ],
)

ray_cc_library(
    name = "task_event_buffer",
    srcs = ["task_event_buffer.cc"],
    hdrs = ["task_event_buffer.h"],
    deps = [
        "//src/ray/gcs/gcs_client:gcs_client_lib",
        "//src/ray/gcs:gcs_pb_util",
        "//src/ray/common:asio",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:export_task_event_cc_proto",
        "//src/ray/protobuf:gcs_cc_proto",
        "//src/ray/util:counter_map",
        "//src/ray/util:event",
        "@boost//:circular_buffer",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/types:optional",
    ],
)

ray_cc_library(
    name = "out_of_order_actor_submit_queue",
    srcs = ["transport/out_of_order_actor_submit_queue.cc"],
    hdrs = ["transport/out_of_order_actor_submit_queue.h"],
    deps = [
        ":actor_submit_queue",
        "//src/ray/common:id",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/types:optional",
    ],
)

ray_cc_library(
    name = "sequential_actor_submit_queue",
    srcs = ["transport/sequential_actor_submit_queue.cc"],
    hdrs = ["transport/sequential_actor_submit_queue.h"],
    deps = [
        "actor_submit_queue",
        "//src/ray/common:id",
        "@com_google_absl//absl/types:optional",
    ],
)

ray_cc_library(
    name = "memory_store",
    srcs = ["store_provider/memory_store/memory_store.cc"],
    hdrs = ["store_provider/memory_store/memory_store.h"],
    deps = [
        ":core_worker_context",
        ":reference_count",
        "//src/ray/common:asio",
        "//src/ray/common:id",
        "//src/ray/common:ray_config",
        "//src/ray/common:status",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "task_manager_interface",
    hdrs = ["task_manager_interface.h"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/common:status",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:common_cc_proto",
        "//src/ray/protobuf:worker_cc_proto",
        "@com_google_absl//absl/types:optional",
    ],
)

ray_cc_library(
    name = "task_manager",
    srcs = ["task_manager.cc"],
    hdrs = ["task_manager.h"],
    deps = [
        ":actor_manager",
        ":memory_store",
        ":task_event_buffer",
        ":task_manager_interface",
        "//src/ray/gcs:gcs_pb_util",
        "//src/ray/common:id",
        "//src/ray/common:ray_object",
        "//src/ray/protobuf:common_cc_proto",
        "//src/ray/protobuf:worker_cc_proto",
        "//src/ray/stats:stats_metric",
        "//src/ray/util",
        "//src/ray/util:counter_map",
        "//src/ray/util:exponential_backoff",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "dependency_resolver",
    srcs = ["transport/dependency_resolver.cc"],
    hdrs = ["transport/dependency_resolver.h"],
    deps = [
        ":actor_creator",
        ":memory_store",
        ":task_manager_interface",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
    ],
)

ray_cc_library(
    name = "actor_task_submitter",
    srcs = ["transport/actor_task_submitter.cc"],
    hdrs = ["transport/actor_task_submitter.h"],
    deps = [
        ":actor_creator",
        ":actor_submit_queue",
        ":core_worker_context",
        ":dependency_resolver",
        ":out_of_order_actor_submit_queue",
        ":sequential_actor_submit_queue",
        "//src/ray/gcs/gcs_client:gcs_client_lib",
        "//src/ray/gcs:gcs_pb_util",
        "//:worker_rpc",
        "//src/ray/common:asio",
        "//src/ray/common:id",
        "//src/ray/common:ray_object",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
    ],
)

ray_cc_library(
    name = "scheduling_util",
    srcs = ["transport/scheduling_util.cc"],
    hdrs = ["transport/scheduling_util.h"],
    deps = [
        "//src/ray/raylet_client:raylet_client_lib",
        "//:rpc_server_call",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:worker_cc_proto",
    ],
)

ray_cc_library(
    name = "normal_scheduling_queue",
    srcs = ["transport/normal_scheduling_queue.cc"],
    hdrs = ["transport/normal_scheduling_queue.h"],
    deps = [
        "scheduling_queue",
        ":scheduling_util",
        "//:rpc_server_call",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "actor_scheduling_queue",
    srcs = ["transport/actor_scheduling_queue.cc"],
    hdrs = ["transport/actor_scheduling_queue.h"],
    deps = [
        ":concurrency_group_manager",
        ":core_worker_fiber",
        ":scheduling_queue",
        ":scheduling_util",
        ":task_event_buffer",
        ":thread_pool",
        "//src/ray/raylet_client:raylet_client_lib",
        "//:rpc_server_call",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:worker_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "concurrency_group_manager",
    srcs = ["transport/concurrency_group_manager.cc"],
    hdrs = ["transport/concurrency_group_manager.h"],
    deps = [
        ":core_worker_fiber",
        ":thread_pool",
        "//src/ray/common:task_common",
    ],
)

ray_cc_library(
    name = "out_of_order_actor_scheduling_queue",
    srcs = ["transport/out_of_order_actor_scheduling_queue.cc"],
    hdrs = ["transport/out_of_order_actor_scheduling_queue.h"],
    deps = [
        ":concurrency_group_manager",
        ":core_worker_fiber",
        ":scheduling_queue",
        ":scheduling_util",
        ":task_event_buffer",
        ":thread_pool",
        "//src/ray/raylet_client:raylet_client_lib",
        "//:rpc_server_call",
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:worker_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "task_receiver",
    srcs = ["transport/task_receiver.cc"],
    hdrs = ["transport/task_receiver.h"],
    deps = [
        ":actor_creator",
        ":actor_handle",
        ":actor_scheduling_queue",
        ":actor_task_submitter",
        ":concurrency_group_manager",
        ":core_worker_common",
        ":core_worker_context",
        ":core_worker_fiber",
        ":dependency_resolver",
        ":memory_store",
        ":normal_scheduling_queue",
        ":out_of_order_actor_scheduling_queue",
        ":thread_pool",
        "//:rpc_server_call",
        "//:worker_rpc",
        "//src/ray/common:asio",
        "//src/ray/common:id",
        "//src/ray/common:ray_object",
        "//src/ray/common:task_common",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "experimental_mutable_object_manager",
    srcs = ["experimental_mutable_object_manager.cc"],
    hdrs = ["experimental_mutable_object_manager.h"],
    deps = [
        "//src/ray/common:ray_config",
        "//src/ray/common:ray_object",
        "//src/ray/common:status",
        "//src/ray/common:task_common",
        "//src/ray/object_manager:object_manager_common",
        "//src/ray/object_manager/plasma:plasma_client",
        "@com_google_absl//absl/container:node_hash_map",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_library(
    name = "future_resolver",
    srcs = ["future_resolver.cc"],
    hdrs = ["future_resolver.h"],
    deps = [
        ":memory_store",
        "//:worker_rpc",
        "//src/ray/common:grpc_util",
        "//src/ray/common:id",
    ],
)

ray_cc_library(
    name = "experimental_mutable_object_provider",
    srcs = ["experimental_mutable_object_provider.cc"],
    hdrs = ["experimental_mutable_object_provider.h"],
    deps = [
        ":experimental_mutable_object_manager",
        "//src/ray/raylet_client:raylet_client_lib",
        "//:rpc_client_call",
    ],
)

ray_cc_library(
    name = "generator_waiter",
    srcs = ["generator_waiter.cc"],
    hdrs = ["generator_waiter.h"],
    deps = [
        ":core_worker_common",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "object_recovery_manager",
    srcs = ["object_recovery_manager.cc"],
    hdrs = ["object_recovery_manager.h"],
    deps = [
        ":memory_store",
        ":reference_count",
        ":task_manager",
        "//src/ray/raylet_client:raylet_client_lib",
        "//src/ray/common:id",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/synchronization",
    ],
)

ray_cc_library(
    name = "profile_event",
    srcs = ["profile_event.cc"],
    hdrs = ["profile_event.h"],
    deps = [
        ":core_worker_context",
        ":task_event_buffer",
        "@com_google_absl//absl/time",
    ],
)

ray_cc_library(
    name = "plasma_store_provider",
    srcs = ["store_provider/plasma_store_provider.cc"],
    hdrs = ["store_provider/plasma_store_provider.h"],
    deps = [
        ":core_worker_common",
        ":core_worker_context",
        ":reference_count",
        "//src/ray/raylet_client:raylet_client_lib",
        "//src/ray/common:id",
        "//src/ray/common:ray_config",
        "//src/ray/common:status",
        "//src/ray/common:task_common",
        "//src/ray/object_manager/plasma:plasma_client",
        "//src/ray/protobuf:gcs_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
    ],
)

ray_cc_library(
    name = "normal_task_submitter",
    srcs = ["transport/normal_task_submitter.cc"],
    hdrs = ["transport/normal_task_submitter.h"],
    deps = [
        ":actor_manager",
        ":core_worker_context",
        ":dependency_resolver",
        ":lease_policy",
        ":memory_store",
        ":task_manager",
        ":task_receiver",
        "//src/ray/raylet_client:raylet_client_lib",
        "//src/ray/gcs:gcs_pb_util",
        "//:worker_rpc",
        "//src/ray/common:id",
        "@com_google_absl//absl/base:core_headers",
    ],
)

ray_cc_library(
    name = "thread_pool",
    srcs = ["transport/thread_pool.cc"],
    hdrs = ["transport/thread_pool.h"],
    deps = [
        "//src/ray/util:logging",
        "@boost//:asio",
        "@boost//:thread",
    ],
)
